home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI717.ASC < prev    next >
Text File  |  1992-02-25  |  2KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  717
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/1
  12.  
  13.     TITLE  :  Getting Amount of Available Memory on the Far Heap
  14.  
  15.  
  16.  
  17.  
  18.   /************************************************************************
  19.       Purpose:
  20.           This function will determine how much memory is available
  21.           on the far heap.
  22.  
  23.       Usage:
  24.           To use this function you must put the statement:
  25.                extern unsigned long heapsize(void);
  26.           within the scope of the calling function.
  27.  
  28.       Method:
  29.           The memory available on the far heap is computed by
  30.           determining the sum of the freed blocks of memory and
  31.           adding that amount to the value returned by coreleft().
  32.  
  33.   ***********************************************************************/
  34.   #include <alloc.h>
  35.   #include <stdio.h>
  36.  
  37.   unsigned long heapsize(void)
  38.   {
  39.      unsigned long i = 0;    /* Return variable */
  40.      struct farheapinfo hi;  /* Value returned from farheapwalk */
  41.      hi.ptr = NULL;          /* Set the beginning of farheapwalk*/
  42.  
  43.      if( farheapcheck() <= 0 )  /* Check for corrupted heap */
  44.         return (-1L);
  45.  
  46.      while( farheapwalk(&hi) == _HEAPOK ) /* Walk the heap and sum
  47.                                              size of free blocks */
  48.           if( hi.in_use == 0 )
  49.              i += hi.size;
  50.  
  51.      i += farcoreleft();  /* Check for amount of free memory from
  52.                              the highest allocated block to the end
  53.                              of DOS */
  54.      return i;
  55.   }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.